home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 12845 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.4 KB  |  58 lines

  1. Path: news.missouri.edu!news  
  2. From: pixel@rhino.coe.missouri.edu (James P. Cooper)
  3. Newsgroups: comp.lang.c
  4. Subject: Reading stdin twice
  5. Date: 3 Apr 1996 02:42:53 GMT
  6. Organization: University of Missouri - Columbia
  7. Message-ID: <4jsojd$1hlk@news.missouri.edu>
  8. Reply-To: pixel@coe.missouri.edu
  9. NNTP-Posting-Host: rhino.coe.missouri.edu
  10. X-Newsreader: knews 0.9.5
  11.  
  12.  
  13. Hi,
  14.  
  15. I'm writing a program, and I'd like two functions to read the stdin
  16. stream.  Is this possible?  I realize I could pass a pointer to the
  17. buffer after the first function fread's stdin, but this would break
  18. something else more serious.
  19.  
  20. Example of what I'm doing:
  21.  
  22. void read_first() {
  23.    char *input;
  24.    FILE *infile;
  25.    
  26.    length = 5000;
  27.    fread(input, sizeof(char), length, stdin);
  28.    
  29.    /*  Do stuff with data here... */
  30. }
  31.  
  32. void read_again() {
  33.    char *input;
  34.    FILE *infile;
  35.    
  36.    length=5000;
  37.    fread(input,sizeof(char),length,stdin);
  38.    
  39.    /* Do something different  */
  40. }
  41.  
  42. I've tried to use fwrite to rewrite the buffer back to stdin, but that
  43. didn't work (presumably because stdin is read-only).
  44.  
  45. Any ideas?
  46.  
  47. Thanks
  48.  
  49. -- James
  50.  
  51. -- 
  52. .........................................................................
  53.                         James Paul Cooper * Pixel
  54.                          MU College of Education
  55.        pixel@coe.missouri.edu - http://tiger.coe.missouri.edu/~pixel/
  56. .........................................................................
  57.  
  58.